package com.project.pushtask.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.pushtask.dto.ParamDto;
import com.project.pushtask.entity.Siji;
import com.project.pushtask.mapper.SijiMapper;
import com.project.pushtask.service.SijiService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SijiServiceImpl implements SijiService {

    @Resource
    private SijiMapper sijiMapper;

    @Override
    @DS("master")
    public List<Siji> getCreateList() {
        return sijiMapper.selectCreateList();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void saveCreateList(List<Siji> list) {
        for (Siji entity : list) {
            sijiMapper.insertSelective(entity);
        }
    }
    @Override
    @DS("secondary")
    public Integer getCount(ParamDto paramDto) {
        return sijiMapper.getCount(paramDto);
    }

    @Override
    @DS("secondary")
    public List<Siji> getList(ParamDto paramDto) {
        return sijiMapper.getList(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void deleteByDate(ParamDto paramDto) {
        sijiMapper.deleteByDate(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void deleteExpireDate(ParamDto paramDto) {
        sijiMapper.deleteExpireDate(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("readbase")
    public void saveList(List<Siji> list) {
        for (Siji entity : list) {
            sijiMapper.insertSelective(entity);
        }
    }

    @Override
    @DS("readbase")
    public Integer getReadBaseCount(ParamDto paramDto) {
        return sijiMapper.getCountReadbase(paramDto);
    }
}
